package com.zw.pdm.module.overview.controller;

import com.zw.pdm.base.BaseController;
import com.zw.pdm.entity.basic.Dept;
import com.zw.pdm.module.overview.model.*;
import com.zw.pdm.module.overview.service.HomeService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

/**
 * @Description: 首页接口
 *
 * 权限：
 * overview:home:view 查看
 *
 * @Author: China.sgl
 * @Date: 2020/8/3 16:11
 */
@Controller
@RequestMapping("/overview/home")
@SuppressWarnings("all")
public class HomeController extends BaseController {

    @Autowired
    private HomeService homeService;

    @GetMapping
    @RequiresPermissions({"overview:home:view"})
    public String page(Model model) {
        model.addAttribute("waitHandler", homeService.getWaitHandler());
        List<Dept> officeList = homeService.findDeptByPid(1);
        int i = 1;
        for (Dept dept : officeList) {
            if (dept.getId() == 31) {
                continue;
            }
            List<Dept> branchList = homeService.findDeptByPid(dept.getId());
            List<String> branchName = new ArrayList<>();
            List<Integer> execCount = new ArrayList<>();
            List<Integer> notStartedCount = new ArrayList<>();
            for (Dept dept1 : branchList) {
                branchName.add(dept1.getName());
                execCount.add(homeService.findExecCount(dept1.getId()));
                notStartedCount.add(homeService.findNotStartedCount(dept1.getId()));
            }
            model.addAttribute("sectionName" + i, branchName.toArray(new String[0]));
            model.addAttribute("sectionExecutingProjectCount" + i, execCount.toArray(new Integer[0]));
            model.addAttribute("sectionNotStartedProjectCount" + i, notStartedCount.toArray(new Integer[0]));
            i++;
        }
        List<Dept> craList = homeService.findDeptByPid(4);

//        i = 1;
//        for (Dept dept : craList) {
//            List<String> craBranchName = new ArrayList<>();
//            List<Integer> craExecCount = new ArrayList<>();
//            List<Integer> craNotStartedCount = new ArrayList<>();
//            for(Dept dept1 : craList){
//                if (dept1.getId() == 34) {
//                    continue;
//                }
//                craBranchName.add(dept1.getName());
//                craExecCount.add(homeService.findCraExecCount(dept1.getId()));
//                craNotStartedCount.add(homeService.findCraNotStartedCount(dept1.getId()));
//            }
//            model.addAttribute("craName" + i, craBranchName.toArray(new String[0]));
//            model.addAttribute("craExecCount" + i, craExecCount.toArray(new Integer[0]));
//            model.addAttribute("craNotCount" + i, craNotStartedCount.toArray(new Integer[0]));
//            i++;
//        }

//        i = 1;
//        for (Dept dept : craList) {
//            List<Integer> craExecCount = new ArrayList<>();
//            List<Integer> craNotStartedCount = new ArrayList<>();
//            for(Dept dept1 : craList){
//                if (dept1.getId() == 34) {
//                    continue;
//                }
//                craExecCount.add(homeService.findCraPartExecCount(dept1.getId()));
//                craNotStartedCount.add(homeService.findCraPartNotStartedCount(dept1.getId()));
//            }
//            model.addAttribute("craPartExecCount" + i, craExecCount.toArray(new Integer[0]));
//            model.addAttribute("craPartNotCount" + i, craNotStartedCount.toArray(new Integer[0]));
//            i++;
//        }
        return "overview/home/page";
    }

    @ResponseBody
    @GetMapping("/box1/year")
    public Box1 box1(Integer year) {
        return homeService.getBox1(year, null);
    }

    @ResponseBody
    @GetMapping("/box1/month")
    public Box1 box1(Integer year, Integer month) {
        return homeService.getBox1(year, month);
    }

    @ResponseBody
    @GetMapping("/box2/year")
    public Box2 box2(Integer year) {
        return homeService.getBox2(year, null);
    }

    @ResponseBody
    @GetMapping("/box2/month")
    public Box2 box2(Integer year, Integer month) {
        return homeService.getBox2(year, month);
    }

    @ResponseBody
    @GetMapping("/box3/year")
    public Box3 box3(Integer year) {
        return homeService.getBox3(year, null);
    }

    @ResponseBody
    @GetMapping("/box3/month")
    public Box3 box3(Integer year, Integer month) {
        return homeService.getBox3(year, month);
    }

    @ResponseBody
    @GetMapping("/box4/year")
    public Box4 box4(Integer year) {
        return homeService.getBox4(year, null);
    }

    @ResponseBody
    @GetMapping("/box4/month")
    public Box4 box4(Integer year, Integer month) {
        return homeService.getBox4(year, month);
    }

    @ResponseBody
    @GetMapping("/box5/year")
    public Box5 box5(Integer year) {
        return homeService.getBox5(year, null);
    }

    @ResponseBody
    @GetMapping("/box5/month")
    public Box5 box5(Integer year, Integer month) {
        return homeService.getBox5(year, month);
    }

    @ResponseBody
    @GetMapping("/box6/year")
    public Box6 box6(Integer year) {
        return homeService.getBox6(year, null);
    }

    @ResponseBody
    @GetMapping("/box6/month")
    public Box6 box6(Integer year, Integer month) {
        return homeService.getBox6(year, month);
    }

    @ResponseBody
    @GetMapping("/box7/year")
    public Box7 box7(Integer year) {
        return homeService.getBox7(year, null);
    }

    @ResponseBody
    @GetMapping("/box7/month")
    public Box7 box7(Integer year, Integer month) {
        return homeService.getBox7(year, month);
    }

    @ResponseBody
    @GetMapping("/box8/year")
    public Box8 box8(Integer year) {
        return homeService.getBox8(year, null);
    }

    @ResponseBody
    @GetMapping("/box8/month")
    public Box8 box8(Integer year, Integer month) {
        return homeService.getBox8(year, month);
    }

}
